package com.gzz.orchid.common.core.tuple;

import com.gzz.orchid.common.core.util.I18nUtil;
import lombok.Value;

import java.time.LocalDate;
import java.util.Objects;

/**
 * 日期范围
 *
 * @author higmd
 */
@Value
public class DateRange {
    LocalDate begin;
    LocalDate end;
    // 构造函数
    public DateRange(LocalDate begin, LocalDate end) {
        if (Objects.isNull(begin)) {
            throw new IllegalArgumentException(I18nUtil.ofMessage("开始日期不能空为空"));
        }
        if (Objects.isNull(end)) {
            throw new IllegalArgumentException(I18nUtil.ofMessage("结束日期不能空为空"));
        }
        if (begin.isAfter(end)) {
            throw new IllegalArgumentException(I18nUtil.ofMessage("结束日期必须在开始时间之前"));
        }
        this.begin = begin;
        this.end = end;
    }

    /**
     * 判断日期是否在范围之内
     *
     * @param d
     * @return
     */
    public boolean isTimeBetween(LocalDate d) {
        return this.begin.isBefore(d) && this.end.isAfter(d);
    }
}
